<?php
if (!defined('ZZQSS')){
	die("Access Denied");
}

class AdminClass {
	var $db;
	var $table;
	var $tablepre;
	function __construct(){
		//设置全局变量
		global $db,$tablepre;
		$this->db=$db;
		$this->tablepre=$tablepre;
		$this->table=$tablepre."admin";
	}
	function AdminClass() {
		$this->__construct();
	}
	function add($sarray){
		if(is_array($sarray)){
			if(!empty($sarray['user'])){
				//插入数据库操作	
				if(is_numeric(inserttable($this->table, $sarray,1)))return "OK";
			}return "缺少参数";
		}return "数据格式错误";
		
	}
	function edit($aid,$sarray){
		if(is_array($sarray) && !empty($aid)){
			if(!empty($sarray['password'])){
				//更新数据库操作
				$wheresqlarr=" aid='{$aid}'";
				updatetable($this->table,$sarray, $wheresqlarr);
				return "OK";
			}return "缺少参数";
		}return "参数错误";
	}
	function del($aid){
		if(is_numeric($aid))
		{
			$this->db->query("delete from {$this->table} where aid={$aid}");
			return "OK";
			
		}else {
			return "参数错误";			
		}
	}	
	
	
	/**
	 * 获取数据数组
	 *
	 * @param string $limit
	 * @param string $where
	 * @param string $orderby
	 * @return array
	 */
	function getdata($limit="",$where="",$orderby=""){
		$tempdata=array();
		if(!empty($limit))$limit=" limit $limit ";
		if(!empty($where))$where=" where $where ";
		if(!empty($orderby))$orderby=" order by $orderby ";else $orderby=" order by aid desc";
		$sql="select * from {$this->table}{$where}{$orderby}{$limit}";
		$query =$this->db->query($sql);
		while($value = $this->db->fetch_array($query)) {
			$tempdata[]=$value;
		}
		return $tempdata;
	
	}
	function getcount($where=""){
	if(!empty($where))$where=" where $where";
	$count= $this->db->result_first("Select count(*) From `$this->table` $where");
	return $count;
	
	}
	
}

?>